/**
**********************************************************************
* @file     main.c
* @brief    对文件的简要说明
* @details  对文件的详细说明
* @author   jcai
* @date     2022-05-07 09:29:30
* @copyright Copyright &copy; 2022 wy1107412334@163.com All rights reserved
* @version  v0.0.1
*
* \n Email:  wy1107412334@163.com
* \n Blog:   None
* \n Github: https://github.com/wy1107412334
* \n Gitee:  https://gitee.com/git.git1107412334.com
*
**********************************************************************
* @note
* None.
**********************************************************************
* @attention
* None.
**********************************************************************
@verbatim
@endverbatim
**********************************************************************
* @par 历史记录
* 1. v0.0.1: jcai, 2022-05-07 09:29:30
*   - 首次编写
*
*<center>Copyright &copy; 2022 wy1107412334@163.com All rights reserved</center>
**********************************************************************
*/

/* 头文件导入区 --------------------------------------------------- */

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL/SDL_video.h>
#include <SDL/SDL_timer.h>
#include "pixel_operation.h"


/**
**********************************************************************
* @brief    简要说明
* @details  详细说明
* @param    none
* @param[in]     a: 该参数用于输入
* @param[in,out] b: 该参数用于输入和输出
* @param[out]    c: 该参数用于输出
* @retval  none
* @retval  0 函数成功
* @retval  1 函数失败
* @return  返回0成功；否则失败
* @note    none
*/
int main(int argc, char *argv[])
{
    SDL_Surface *screen;
    int quit = 0;
    SDL_Event event;
    uint32_t x,y, xw, yh;
    uint32_t w = 10, h = 10;
    uint32_t color;
    int i = 0;

    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
    {
        fprintf(stderr, "SDL 初始化失败！\n");
        return EXIT_FAILURE;
    }

    screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE);
    if (!screen)
    {
        fprintf(stderr, "创建屏幕表面失败！\n");
        goto exit_1;
    }

    srand(SDL_GetTicks());

    while (!quit)
    {
        while (SDL_PollEvent(&event))
        {
            if (event.type == SDL_QUIT)
                quit = 1;
        }

        while ((i++ % 20) == 0)
        {
            SDL_FillRect(screen, &screen->clip_rect,
                         SDL_MapRGB(screen->format, 0xff, 0xff, 0xff));


            x = rand() % (640 - w);
            xw = x + w;
            y = rand() % (480 - h);
            yh = y + h;
            for (; y < yh; y++)
            {
                for (x = xw - w; x < xw; x++)
                {
                    color = SDL_MapRGB(screen->format, rand() % 255,
                                       rand() % 255, rand() % 255);
                    setPixel32(screen, x, y, color);
                }
            }

            SDL_Flip(screen);
        }

        SDL_Delay(10);
    }


exit_1:
    SDL_Quit();

    return 0;
}




/***  Copyright (C) 2022 wy1107412334@163.com All rights reserved ***/
/****************************** END OF FILE *************************/

